package hu.jonas.allunit.views;

import hu.jonas.allunit.model.TestResult;

import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;

public class TestResultTableLabelProvider implements ITableLabelProvider {

	private IconProvider iconProvider;

	public TestResultTableLabelProvider() {
		this.iconProvider = new IconProvider();
	}
	
	protected TestResultTableLabelProvider(IconProvider iconProvider) {
		this.iconProvider = iconProvider;
	}
	
	@Override
	public Image getColumnImage(Object element, int columnIndex) {
		if (element instanceof TestResult) {
			TestResult item = (TestResult) element;

			if (columnIndex == 0) {
				switch (item.getOutcome()) {
				case Ok:
					return iconProvider.getIcon("/icons/testok.gif");
				default:
					return iconProvider.getIcon("/icons/testfail.gif");
				}
			}
		}
		
		return null;
	}

	@Override
	public String getColumnText(Object element, int columnIndex) {
		if (element instanceof TestResult) {
			TestResult item = (TestResult) element;

			switch (columnIndex) {
			case 0:
				return item.getTestClassName();
			case 1:
				return item.getTestMethodName();
			case 2:
				return String.format("%1$4.3f", item.getElapsedTime());
			}
		}
		
		return null;
	}

	@Override
	public void addListener(ILabelProviderListener listener) {

	}

	@Override
	public void dispose() {
	}

	@Override
	public boolean isLabelProperty(Object element, String property) {
		return false;
	}

	@Override
	public void removeListener(ILabelProviderListener listener) {
	}

	public void setIconProvider(IconProvider iconProvider) {
		this.iconProvider = iconProvider;
	}

}
